#pragma once
/*
 * @Author: hzm 
 * @Date: 2020-06-11 22:33:28 
 * @Last Modified by: hzm
 * @Last Modified time: 2020-06-11 23:08:44
 */

#include <mutex>


template <typename T>

class Singleton {

public:

    static T& instance() {
        std::call_once(_onceFlag,[]() {
            _instance = new T();
        });

        return _instance;
    }
    

private:

    Singleton();
    ~Singleton();

    Singleton(const Singleton& other);
    Singleton &operator=(const Singleton& other);

    static std::once_flag _onceFlag;
    static T* _instance;

};

template <typename T>
T* Singleton<T>::_instance = nullptr;




